<template>
    <div class="e-form" v-if="state === 'main'">
        <!-- <div class="title">
                <img src="@/assets/test.png" alt="" />
                <span>外包商入库</span>
                <i class="el-icon-full-screen" @click="handleFullScreen"></i>
            </div> -->
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <div style="width: 100%" class="form">
                <el-form :model="formData" label-width="170px" :rules="rules" ref="ruleForm">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="招标编号：">
                                <div style="display: flex">
                                    <el-input v-model="formData.tenderApplyNo" disabled></el-input>
                                    <ComShowBiddingButton :tenderId="tenderId" mod="hire" />
                                </div>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="招标单位：">
                                <span>{{ formData.tenderApplyOrgName }}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="拟招标项目名称：">
                                <span>{{ formData.projectName }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="登记日期：">
                                <el-date-picker
                                    v-model="formData.reportTime"
                                    type="date"
                                    placeholder="选择日期"
                                >
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="租赁方式：">
                                <span v-if="formData.tenderForm">{{
                                    formData.tenderForm | tenderForm(this)
                                }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="招标类型：">
                                <span>{{ formData.tenderClass | tenderClass(this) }}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="申请机构：">
                                <span>{{ formData.tenderApplyCompanyName }}</span>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="录入机构：">
                                <span>{{ front.orgName }}</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <!-- <el-col :span="12">
                            <el-form-item label="登记日期：">
                                <el-date-picker v-model="formData.reportTime" type="date" placeholder="选择日期" :clearable="false" disabled>
                                </el-date-picker>
                            </el-form-item>
                        </el-col> -->
                        <el-col :span="12">
                            <el-form-item label="状态：">
                                <span>草稿</span>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-form-item label="评标记录：" prop="evaluationRecord">
                            <el-input
                                type="textarea"
                                :rows="2"
                                placeholder="请输入内容"
                                v-model="formData.evaluationRecord"
                                style="margin-right: 110px"
                            >
                            </el-input>
                        </el-form-item>
                    </el-row>
                    <el-row>
                        <el-form-item label="备注：">
                            <el-input
                                type="textarea"
                                :rows="2"
                                placeholder="请输入内容"
                                v-model="formData.remarks"
                                style="margin-right: 110px"
                            >
                            </el-input>
                        </el-form-item>
                    </el-row>
                </el-form>
            </div>
        </div>
        <div class="buttons">
            <!-- <span class="tip"
                    ><span style="color: red; margin-right: 0">*</span
                    >为必填项</span
                > -->
            <!-- <el-button
                    type="primary"

                    class="btn-blue"
                    >打印</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >删除</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >发布</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >审核</el-button
                >
                <el-button
                    type="primary"

                    class="btn-blue"
                    >撤回</el-button
                > -->
            <el-button type="primary" class="btn-blue" @click="submit">保存</el-button>
            <el-button @click="handleClose">取消</el-button>
        </div>
    </div>
</template>

<script>
// import ComTreeTable from '@/templates/table/treeTable.vue'
// import ComTreeFile from '@/templates/table/treeFile.vue'
// import ComPagination from '@/components/pagination/pagination.vue'
// import resultRequest from '@/api/tender/result.js'
import applyRequest from '@/api/tender/apply.js'
import materialZhouCaiLeasingRequest from '@/api/tender/materialZhouCaiLeasing.js'
import ComShowBiddingButton from '@/pages/bidding/common/showBiddingButton.vue'
import { mapState } from 'vuex'

export default {
    data () {
        return {
            state: 'main',
            // dialogVisible: false,
            // fullscreen: false,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableData: [],
            value: '',
            textarea: '',
            formData: {
                evaluationRecord: '',
                projectName: '',
                remarks: '',
                reportTime: '',
                tenderApplyId: '',
                tenderApplyNo: '',
                tenderApplyOrgId: '',
                tenderApplyOrgName: '',
                tenderClass: 4,
                tenderForm: ''
            },
            test: '',
            selectData: [],
            selectTableColumnAttr: [
                {
                    label: '单据编号',
                    prop: 'billNo'
                },
                {
                    label: '拟招标项目名称',
                    prop: 'tenderName'
                },
                {
                    label: '单据日期',
                    prop: 'gmtCreate'
                },
                {
                    label: '单据机构名称',
                    prop: 'orgName'
                }
            ],
            selectTableColumnWidth: {
                leftWidth: '150',
                rightWidth: '100'
            },
            selectDataPagination: {},
            // 前端展示不传给后端的数据
            front: {
                applyOrgName: '', //申请机构
                orgName: '' //录入机构
            },
            rules: {
                // tenderApplyNo: {
                //     required: true,
                //     message: '请输入招标编号',
                //     trigger: 'blur'
                // },
                tenderApplyOrgName: {
                    required: true,
                    message: '请输入招标单位',
                    trigger: 'blur'
                },
                projectName: {
                    required: true,
                    message: '请输入拟招标项目名称',
                    trigger: 'blur'
                },
                reportTime: {
                    required: true,
                    message: '请输入登记日期',
                    trigger: 'blur'
                },
                tenderForm: {
                    required: true,
                    message: '请输入租赁方式',
                    trigger: 'blur'
                },
                tenderClass: {
                    required: true,
                    message: '请输入招标类型',
                    trigger: 'blur'
                },
                // state: {
                //     required: true,
                //     message: '请输入状态',
                //     trigger: 'blur'
                // },
                evaluationRecord: {
                    required: true,
                    message: '请输入评标记录',
                    trigger: 'blur'
                }
            }
        }
    },
    computed: {
        ...mapState({
            options: state => state.biddingApplication.dictionaries
        }),
        tenderId () {
            return this.$route.query.tenderId || this.$route.query.billid
        }
    },
    components: {
        // ComTreeTable,
        // ComTreeFile,
        // ComPagination,
        ComShowBiddingButton
    },
    created () {
        this.init()
    },
    mounted () {},
    methods: {
        getNowDate () {
            // 个位数前补0
            const zeroFill = function (num) {
                if (parseInt(num) < 10) {
                    num = '0' + num
                }
                return num
            }
            let nowtime = new Date()
            nowtime =
                zeroFill(nowtime.getFullYear()) +
                '-' +
                zeroFill(nowtime.getMonth() + 1) +
                '-' +
                zeroFill(nowtime.getDate())
            return nowtime
            // this.$set(this.formData, 'reportTime', nowtime)
        },
        selectChange (kvId, label) {
            if (label === '租赁方式') {
                this.options.tenderForm.forEach(item => {
                    if (kvId === item.value) {
                        this.formData.tenderFormName = item.label
                    }
                })
            } else if (label === '币种') {
                this.options.currency.forEach(item => {
                    if (item.kvValue === kvId) {
                        this.formData.currency = item.kvKey
                    }
                })
            }
        },
        async init () {
            await materialZhouCaiLeasingRequest.applyGetById({ id: this.tenderId }).then(res => {
                // 招标申请id
                this.formData.tenderApplyId = res.billId
                // 招标申请编号
                this.formData.tenderApplyNo = res.billNo
                // 	拟招标项目名称
                this.formData.projectName = res.tenderName
                // 	租赁方式
                this.formData.tenderForm = res.tenderForm
                // 	登记日期
                this.formData.reportTime = this.getNowDate()
                // 	招标单位
                this.formData.tenderApplyOrgId = res.tenderUserId
                this.formData.tenderApplyOrgName = res.tenderUser
                // 申请机构
                this.formData.tenderApplyCompanyName = res.applyOrgName
                this.formData.tenderApplyCompanyId = res.applyOrgId
                // 录入机构
                this.front.orgName = this.$store.state.userInfo.orgInfo.orgName
                // 表单提交信息映射基础招标信息
                // const tenderData = res
                // Object.keys(this.formData).forEach(formDataKey => {
                //     Object.keys(tenderData).forEach(tenderDataKey => {
                //         if (formDataKey === tenderDataKey) {
                //             this.formData[formDataKey] = tenderData[tenderDataKey]
                //         }
                //     })
                // })
                // // 部分数据对应不上，需要增改
                // this.formData.tenderApplyId = tenderData.billId // res的billid是招标id，新增补遗招标id是tenderApplyId
                // this.formData.tenderApplyNo = tenderData.billNo
                // delete this.formData.billId // 新增不需要表单的billId
                // delete this.formData.billNo
                // this.formData.tenderApplyOrgId = res.applyOrgId
                // this.formData.tenderApplyOrgName = res.applyOrgName
                // this.formData.projectName = res.tenderName
                // this.formData.remarks = ''
            })
        },
        showBidding () {
            if (!this.tenderId) return // 前期需求可切换，现在不需要
            this.$notify.closeAll()
            this.$notify({
                title: '查看招标详情',
                dangerouslyUseHTMLString: true,
                message: `正式环境：客户端打开新页面<br>
                测试环境：手动打开新页面<br>
                <textarea cols="35" rows="10">http://localhost:8080/biddingApplicationShow?tenderId=${this.tenderId}</textarea>
                `,
                duration: 0
            })
        },
        selectCurrentChange (page) {
            this.tenderApplyQueryPage({ limit: 20, page })
        },
        selectDataSearch (searchValue) {
            this.tenderApplyQueryPage({ key: searchValue, limit: 20, page: 1 })
        },
        selectDataConfirm (data) {
            this.state = 'main'
            this.formData.applyOrgName = data.orgName
            this.formData.applyOrgId = data.orgId
        },
        tenderApplyNoInputFocus () {
            this.$refs.tenderApplyNoInput.blur()
        },
        stateChange (name) {
            this.state = name
            if (name === 'selectData') {
                this.tenderApplyQueryPage()
            }
        },
        tenderApplyQueryPage (params = { limit: 20, page: 1 }) {
            applyRequest.tenderApplyQueryPage(params).then(res => {
                this.selectData = res.list
                this.selectDataPagination.total = res.totalCount
            })
        },
        // dialogCloseHook () {
        //     this.initData()
        // },
        // initData () {
        //     this.formData = {
        //         state: 0
        //     }
        // },
        submit () {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    materialZhouCaiLeasingRequest.resultCreate(this.formData).then(res => {
                        const callBack = () => {
                            this.$router.push({
                                path: './hireBidEvaluationResultEdit',
                                query: { billid: res }
                            })
                        }
                        const cancelCallBack = () => {
                            this.$router.push({
                                path: './hireBiddingApplicationEdit',
                                query: { billid: this.tenderId, seat: 'bidEvaluation' }
                            })
                        }
                        this.clientPop(
                            'suc',
                            '保存成功，是否继续？',
                            callBack,
                            null,
                            cancelCallBack
                        )
                    })
                }
            })
        },
        // getVuexData () {
        //     // 获取保存在vuex的数据
        //     this.formData = {
        //         ...this.formData,
        //         ...JSON.parse(
        //             JSON.stringify(
        //                 this.$store.state.biddingApplication.formData
        //             )
        //         )
        //     }
        //     // 获取保存在vuex的常量
        //     if (Object.keys(this.$store.state.userInfo.orgInfo).length !== 0) {
        //         this.formData.orgId = this.$store.state.userInfo.orgInfo.orgId
        //         this.formData.orgName =
        //             this.$store.state.userInfo.orgInfo.orgName
        //     }
        //     console.log('this.formData1', this.formData)
        // },
        handleFullScreen () {
            this.fullscreen = !this.fullscreen
        },
        handleClose () {
            this.$router.push({
                path: './hireBiddingApplicationEdit',
                query: { billid: this.tenderId, seat: 'bidEvaluation' }
            })
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    /* .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    } */
}
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;

    /* .top {
    .left {
      padding: 20px;
      padding-top: 0px;
    }
  } */
}

.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>
